﻿using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;

namespace UnityConfiguration.Infrastructure
{
    public abstract class TypeResolvingCollection<T> : ObservableCollection<T>, IResolvesTypes where T : class, IResolvesTypes
    {
        private UnityTypeResolver _TypeResolver;

        /// <summary>
        /// Get or set the type resolver.
        /// </summary>
        internal UnityTypeResolver TypeResolver {
            get { return _TypeResolver; }
            set {
                _TypeResolver = value;
                foreach (var item in this) {
                    item.TypeResolver = this.TypeResolver;
                }
            }
        }
        #region IResolvesTypes Members

        UnityTypeResolver IResolvesTypes.TypeResolver {
            get { return this.TypeResolver; }
            set { this.TypeResolver = value; }
        }

        #endregion

        public TypeResolvingCollection()
            : base() {
        }

        public TypeResolvingCollection(IEnumerable<T> list)
            : base() {
            foreach (var item in list) {
                this.Add(item);
            }
        }
    }
}
